package tolgahan.albayrak.as3.reflection
{
	public class StaticPropertyInfo extends StaticVariableInfo
	{
		private static const READONLY:String = "readonly";
		private static const WRITEONLY:String = "writeonly";
		
		protected var _canRead:Boolean;
		protected var _canWrite:Boolean;
		
		public function StaticPropertyInfo(xml:XML, baseType:Type, memberIndex:uint)
		{
			super(xml, baseType, memberIndex);
			switch(String(xml.@access[0]))
			{
				case READONLY:
					_canRead = true;
					break;
				case WRITEONLY:
					_canWrite = true;
					break;
				default:
					_canRead = _canWrite = true;
					break;
			}			
		}
		
		public function get canRead():Boolean
		{
			return _canRead;
		}
		
		public function get canWrite():Boolean
		{
			return _canWrite;
		}
		
		override public function get value() : *
		{
			if(_canRead)
				return super.value;
		}
		
		override public function set value(v:*) : void
		{
			if(_canWrite)
				super.value = v;
		}
		
		override public function toString() : String
		{
			var s:String = "private var m_" + _name + ":" + _type + ";";
			if(_canRead)
				s += "\n\t\tpublic static function get " + _name + "():" + _type + "\n\t\t{\n\t\t\treturn m_" + _name + ";\n\t\t}";
			if(_canWrite)
				s += "\n\t\tpublic static function set " + _name + "(v:" + _type + "):void\n\t\t{\n\t\t\tm_" + _name + " = v;\n\t\t}";
			return s;

		}
	}
}